import 'initialize_items.dart';
import 'package:flutter/material.dart';

class XJMainScreen extends StatefulWidget {
  @override
  _XJMainScreenState createState() => _XJMainScreenState();
}

class _XJMainScreenState extends State<XJMainScreen> {
  int _currentIndex = 0;
@override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  /*
  * 1.自己写widget
  * 2.某些widget中会创建RenderObject
  * 3.每一个widget都会创建一个Element对象
  * 4.1.ComponentElement:mount方法-> firstBuild -> rebuild -> performBuild -> build -> _widget.build
  * 4.2.RenderObjectElement:mount方法-> _widget.createRenderObject
  * 4.3.statefulElement:构造方法中 _state = widget.createState()
  *   _state._widget = widget
  * */

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: Colors.red,
        unselectedItemColor: Colors.grey,
        selectedFontSize: 14.0,
        unselectedFontSize: 14.0,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        items: barItems,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}
